﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;

using SBPweb.Modules.Modularity;
using SBPweb.Modules.Smartparts;

using SBPweb.MediaCenter.Tools.WPF.Extenders;

namespace SBPweb.MediaCenter.Modules.Player.WPF.Controls
{
    /// <summary>
    /// Interaction logic for MainMenuItem.xaml
    /// </summary>
    public partial class MainMenuItem : UserControl, IMenuItem
    {

        #region Private fields

        private TagDictionary tag = new TagDictionary();

        #endregion

        #region Constructor logic

        public MainMenuItem()
        {
            InitializeComponent();
            TagDictionary.SetTag(this, tag);
            Scale = new Vector3D(1.0f, 1.0f, 1.0f);

            //RenderTargetBitmap rtb = new RenderTargetBitmap((int)this.Width, (int)this.Height, 96d, 96d, PixelFormats.Pbgra32);
            //DrawingVisual drawingVisual = new DrawingVisual();
            //DrawingContext drawingContext = drawingVisual.RenderOpen();
            //drawingContext.DrawImage(imgIcon.Source, new Rect(new Size(this.Width, this.Height)));
            //drawingContext.Close();
            //rtb.Render(drawingVisual);
            //rtb.Freeze();
            //AsImageSource = rtb;
            AsImageSource = imgIcon.Source;
        }

        #endregion

        #region Property accessors

        public string Text
        {
            get
            {
                return labText.Content.ToString();
            }
            set
            {
                labText.Content = value;
            }
        }

        public Vector3D Scale
        {
            get
            {
                return tag.Get<string, Vector3D>("Scale");
            }
            set
            {
                tag.Put<string, Vector3D>("Scale", value);
            }
        }

        public Vector3D Offset
        {
            get
            {
                return tag.Get<string, Vector3D>("Offset");
            }
            set
            {
                tag.Put<string, Vector3D>("Offset", value);
            }
        }

        public Color BackgroundColor
        {
            get
            {
                return tag.Get<string, Color>("BackgroundColor");
            }
            set
            {
                tag.Put<string, Color>("BackgroundColor", value);
            }
        }

        public ImageSource AsImageSource
        {
            get
            {
                return tag.Get<string, ImageSource>("AsImageSource");
            }
            set
            {
                tag.Put<string, ImageSource>("AsImageSource", value);
            }
        }

        public IModule ParentModule
        {
            get
            {
                return tag.Get<string, IModule>("ParentModule");
            }
            set
            {
                tag.Put<string, IModule>("ParentModule", value);
            }
        }

        #endregion

        #region Events

        public event EventHandler<MenuEventArgs> Pressed;

        public event EventHandler<MenuEventArgs> Selected;

        #endregion

        #region Methods

        public void Press()
        {
            if (Pressed != null)
            {
                Pressed(this, new MenuEventArgs(this));
            }
        }

        public void Select()
        {
            if (Selected != null)
            {
                Selected(this, new MenuEventArgs(this));
            }
        }

        #endregion
    }
}
